package org.xiangxji.snippets.encript;

import java.io.IOException;

import org.junit.Test;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

@SuppressWarnings("restriction")
public class Base64Coding {
	
	private static BASE64Encoder encoder = new sun.misc.BASE64Encoder();   
    private static BASE64Decoder decoder = new sun.misc.BASE64Decoder();   
    public Base64Coding() {}   
    public static String encode (String s)  
    {   
        return encoder.encode(s.getBytes());  
        }   
    public static String decode (String s){   
        try {  
            byte[] temp = decoder.decodeBuffer(s);  
            return new String(temp);  
            } catch (IOException ioe) {   
                // handler  
            }  
        return s;  
    } 

    @Test
    public void testEncode() {
    	String s = "我是中国人";
    	System.out.println(Base64Coding.encode(s));
    	String d = "5oiR5piv5Lit5Zu95Lq6";
    	System.out.println(Base64Coding.decode(d));
    }
}
